import * as UserDao from '../../dao/UserDao'
import { NavigationActions, createAction, AsyncStorage } from '../../utils';
export default {
  namespace: 'app',
  state: {
    showLogin: false
  },
  reducers: {
    updateState(state, { payload }) {
      return { ...state, ...payload }
    },
  },
  effects: {
    //初始化App
    *launchApp(action, { call, put }) {
      const data = yield call(AsyncStorage.get, "userInfo");
      if (data != null) {
        yield put(createAction('user/updateState')({
          userInfo: data
        }))
        yield put(NavigationActions.navigate({ routeName: 'Main' }))
      } else {
        yield put(createAction('updateState')({
          showLogin: true
        }))
      }
    },

  },
}